package com.kqb.controller;


import cn.hutool.core.bean.BeanUtil;
import com.kqb.common.domain.AjaxResult;
import com.kqb.common.domain.page.Page;
import com.kqb.common.domain.page.PageResult;
import com.kqb.pojo.ForwarderInquiryList;
import com.kqb.query.ForwarderInquiryQuery;
import com.kqb.service.ForwarderInquiryListService;
import com.kqb.service.ForwarderInquiryProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api")
@Api(tags = "货代询价")
public class ForwarderInquiryController {

    @Autowired
    ForwarderInquiryListService inquiryListService;

    @Autowired
    ForwarderInquiryProductService inquiryProductService;

    @ApiOperation("保存询价单")
    @PostMapping("/forwarderInquiry")
    public AjaxResult save(@RequestBody ForwarderInquiryList entity) {
        System.out.println(entity);
        int save = inquiryListService.save(entity);
        return AjaxResult.success(save);
    }

    @ApiOperation("查询询价列表")
    @PostMapping("/forwarderInquiry/list")
    public AjaxResult query(@RequestBody ForwarderInquiryQuery inquiryQuery) {
        PageResult pageResult = inquiryListService.queryByMap(BeanUtil.beanToMap(inquiryQuery));
        return AjaxResult.success("货代询价列表",pageResult);
    }

    @ApiOperation("查询询价产品")
    @PostMapping("/forwarderInquiry/product")
    public AjaxResult queryProduct(@RequestBody Page page){
        PageResult pageResult = inquiryProductService.queryByMap(BeanUtil.beanToMap(page));
        return AjaxResult.success("货代询价产品",pageResult);
    }

    @ApiOperation("询价详情")
    @GetMapping("/forwarderInquiry")
    public AjaxResult getInquiry(@RequestParam(required = true) String id) {
        ForwarderInquiryList list = inquiryListService.queryByCode(id);
        return AjaxResult.success("询价详情",list);
    }

    @ApiOperation("更新询价详情")
    @PutMapping("/forwarderInquiry")
    public AjaxResult updateInquiry(@RequestBody ForwarderInquiryList entity) {
        int i = inquiryListService.updateInquiry(entity);
        return AjaxResult.success("更新成功", i);
    }


}
